{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "WARNING:tensorflow:From /root/anaconda3/envs/mytf/lib/python3.8/site-packages/tensorflow/python/compat/v2_compat.py:96: disable_resource_variables (from tensorflow.python.ops.variable_scope) is deprecated and will be removed in a future version.\n",
      "Instructions for updating:\n",
      "non-resource variables are not supported in the long term\n"
     ]
    }
   ],
   "source": [
    "import numpy as np\n",
    "import matplotlib.pyplot as plt\n",
    "import tensorflow.compat.v1 as tf\n",
    "tf.disable_v2_behavior()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "learning_rate =0.1\n",
    "training_epochs=2000\n",
    "def sigmoid(x):\n",
    "    return 1./(1.+np.exp(-x))\n",
    "\n",
    "x1_label1=np.random.normal(3,1,1000)\n",
    "x2_label1=np.random.normal(2,1,1000)\n",
    "x1_label2=np.random.normal(7,1,1000)\n",
    "x2_label2=np.random.normal(6,1,1000)\n",
    "\n",
    "x1s=np.append(x1_label1,x1_label2)\n",
    "x2s=np.append(x2_label1,x2_label2)\n",
    "ys=np.asarray([0.]* len(x1_label1)+[1.]*len(x1_label2))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "X1=tf.placeholder(tf.float32,shape=(None,),name='x1')\n",
    "X2=tf.placeholder(tf.float32,shape=(None,),name='x2')\n",
    "Y=tf.placeholder(tf.float32,shape=(None,),name='y')\n",
    "w=tf.Variable([0.,0.,0.],name='w',trainable=True)\n",
    "\n",
    "y_model=tf.sigmoid(w[2]*X2 + w[1]*X1 + w[0])\n",
    "cost=tf.reduce_mean(-tf.log(y_model*Y + (1-y_model)*(1 - Y)))\n",
    "train_op=tf.train.GradientDescentOptimizer(learning_rate).minimize(cost)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0 0.69314593\n",
      "1 0.6087666\n",
      "2 0.60158926\n",
      "3 0.5965212\n",
      "4 0.5916013\n",
      "5 0.5868137\n",
      "6 0.58215237\n",
      "7 0.57761204\n",
      "8 0.57318825\n",
      "9 0.56887525\n",
      "10 0.5646687\n",
      "11 0.5605644\n",
      "12 0.55655706\n",
      "13 0.55264413\n",
      "14 0.54882056\n",
      "15 0.54508287\n",
      "16 0.54142773\n",
      "17 0.5378515\n",
      "18 0.5343509\n",
      "19 0.53092325\n",
      "20 0.5275652\n",
      "21 0.5242745\n",
      "22 0.52104795\n",
      "23 0.5178833\n",
      "24 0.5147782\n",
      "25 0.51173025\n",
      "26 0.5087372\n",
      "27 0.5057972\n",
      "28 0.50290823\n",
      "29 0.50006837\n",
      "30 0.49727583\n",
      "31 0.4945288\n",
      "32 0.49182606\n",
      "33 0.48916578\n",
      "34 0.48654646\n",
      "35 0.48396692\n",
      "36 0.48142552\n",
      "37 0.4789213\n",
      "38 0.476453\n",
      "39 0.47401944\n",
      "40 0.47161934\n",
      "41 0.4692519\n",
      "42 0.46691597\n",
      "43 0.46461096\n",
      "44 0.46233532\n",
      "45 0.4600887\n",
      "46 0.45786992\n",
      "47 0.45567864\n",
      "48 0.45351368\n",
      "49 0.45137432\n",
      "50 0.44926026\n",
      "51 0.4471706\n",
      "52 0.44510463\n",
      "53 0.44306177\n",
      "54 0.44104138\n",
      "55 0.43904316\n",
      "56 0.43706647\n",
      "57 0.4351106\n",
      "58 0.43317494\n",
      "59 0.4312599\n",
      "60 0.4293639\n",
      "61 0.42748708\n",
      "62 0.425629\n",
      "63 0.42378923\n",
      "64 0.42196724\n",
      "65 0.42016268\n",
      "66 0.41837555\n",
      "67 0.4166052\n",
      "68 0.4148509\n",
      "69 0.4131131\n",
      "70 0.41139093\n",
      "71 0.40968454\n",
      "72 0.40799344\n",
      "73 0.40631694\n",
      "74 0.40465528\n",
      "75 0.40300804\n",
      "76 0.40137506\n",
      "77 0.39975604\n",
      "78 0.39815068\n",
      "79 0.39655858\n",
      "80 0.3949801\n",
      "81 0.3934145\n",
      "82 0.39186165\n",
      "83 0.39032146\n",
      "84 0.38879386\n",
      "85 0.38727835\n",
      "86 0.38577497\n",
      "87 0.3842834\n",
      "88 0.38280368\n",
      "89 0.38133532\n",
      "90 0.37987834\n",
      "91 0.37843275\n",
      "92 0.3769981\n",
      "93 0.3755744\n",
      "94 0.37416124\n",
      "95 0.37275884\n",
      "96 0.371367\n",
      "97 0.36998567\n",
      "98 0.36861423\n",
      "99 0.36725292\n",
      "100 0.3659018\n",
      "101 0.36456007\n",
      "102 0.36322838\n",
      "103 0.36190632\n",
      "104 0.3605935\n",
      "105 0.3592903\n",
      "106 0.35799628\n",
      "107 0.3567113\n",
      "108 0.35543543\n",
      "109 0.3541684\n",
      "110 0.35291046\n",
      "111 0.35166094\n",
      "112 0.35042024\n",
      "113 0.34918824\n",
      "114 0.3479644\n",
      "115 0.34674916\n",
      "116 0.34554198\n",
      "117 0.34434307\n",
      "118 0.34315223\n",
      "119 0.34196955\n",
      "120 0.34079465\n",
      "121 0.33962744\n",
      "122 0.3384683\n",
      "123 0.33731687\n",
      "124 0.3361729\n",
      "125 0.33503643\n",
      "126 0.33390766\n",
      "127 0.33278617\n",
      "128 0.33167198\n",
      "129 0.33056498\n",
      "130 0.32946512\n",
      "131 0.3283725\n",
      "132 0.3272869\n",
      "133 0.32620814\n",
      "134 0.32513636\n",
      "135 0.3240716\n",
      "136 0.32301342\n",
      "137 0.3219619\n",
      "138 0.32091704\n",
      "139 0.3198789\n",
      "140 0.31884736\n",
      "141 0.31782207\n",
      "142 0.31680337\n",
      "143 0.315791\n",
      "144 0.31478512\n",
      "145 0.31378517\n",
      "146 0.31279144\n",
      "147 0.31180406\n",
      "148 0.31082246\n",
      "149 0.30984706\n",
      "150 0.30887762\n",
      "151 0.30791405\n",
      "152 0.30695665\n",
      "153 0.30600467\n",
      "154 0.30505872\n",
      "155 0.3041183\n",
      "156 0.3031837\n",
      "157 0.3022547\n",
      "158 0.3013313\n",
      "159 0.30041334\n",
      "160 0.29950097\n",
      "161 0.29859394\n",
      "162 0.29769233\n",
      "163 0.29679605\n",
      "164 0.29590508\n",
      "165 0.29501948\n",
      "166 0.29413903\n",
      "167 0.29326364\n",
      "168 0.29239345\n",
      "169 0.29152843\n",
      "170 0.2906684\n",
      "171 0.28981334\n",
      "172 0.28896332\n",
      "173 0.28811806\n",
      "174 0.28727794\n",
      "175 0.28644252\n",
      "176 0.28561184\n",
      "177 0.28478613\n",
      "178 0.2839649\n",
      "179 0.2831485\n",
      "180 0.2823368\n",
      "181 0.28152966\n",
      "182 0.28072706\n",
      "183 0.27992907\n",
      "184 0.27913556\n",
      "185 0.2783466\n",
      "186 0.27756214\n",
      "187 0.27678192\n",
      "188 0.27600613\n",
      "189 0.27523455\n",
      "190 0.27446744\n",
      "191 0.27370453\n",
      "192 0.2729458\n",
      "193 0.27219152\n",
      "194 0.2714413\n",
      "195 0.2706951\n",
      "196 0.26995313\n",
      "197 0.2692152\n",
      "198 0.2684813\n",
      "199 0.2677514\n",
      "200 0.26702553\n",
      "201 0.26630354\n",
      "202 0.26558545\n",
      "203 0.2648714\n",
      "204 0.26416117\n",
      "205 0.2634547\n",
      "206 0.26275215\n",
      "207 0.2620533\n",
      "208 0.2613582\n",
      "209 0.26066685\n",
      "210 0.25997922\n",
      "211 0.25929523\n",
      "212 0.25861484\n",
      "213 0.25793806\n",
      "214 0.25726494\n",
      "215 0.2565954\n",
      "216 0.2559293\n",
      "217 0.25526676\n",
      "218 0.25460777\n",
      "219 0.25395206\n",
      "220 0.2532999\n",
      "221 0.25265113\n",
      "222 0.25200582\n",
      "223 0.2513637\n",
      "224 0.25072503\n",
      "225 0.2500897\n",
      "226 0.24945755\n",
      "227 0.24882872\n",
      "228 0.24820316\n",
      "229 0.2475807\n",
      "230 0.24696146\n",
      "231 0.24634545\n",
      "232 0.24573255\n",
      "233 0.24512284\n",
      "234 0.24451612\n",
      "235 0.24391253\n",
      "236 0.24331199\n",
      "237 0.24271452\n",
      "238 0.24212004\n",
      "239 0.24152859\n",
      "240 0.24093997\n",
      "241 0.24035448\n",
      "242 0.23977189\n",
      "243 0.23919208\n",
      "244 0.23861529\n",
      "245 0.2380413\n",
      "246 0.23747012\n",
      "247 0.23690182\n",
      "248 0.23633637\n",
      "249 0.23577365\n",
      "250 0.23521368\n",
      "251 0.23465656\n",
      "252 0.23410212\n",
      "253 0.23355035\n",
      "254 0.23300134\n",
      "255 0.23245488\n",
      "256 0.23191123\n",
      "257 0.23137017\n",
      "258 0.23083173\n",
      "259 0.23029578\n",
      "260 0.22976251\n",
      "261 0.22923179\n",
      "262 0.22870371\n",
      "263 0.22817813\n",
      "264 0.22765493\n",
      "265 0.22713436\n",
      "266 0.22661628\n",
      "267 0.22610053\n",
      "268 0.22558731\n",
      "269 0.22507657\n",
      "270 0.22456819\n",
      "271 0.22406214\n",
      "272 0.22355857\n",
      "273 0.22305743\n",
      "274 0.22255844\n",
      "275 0.22206195\n",
      "276 0.22156778\n",
      "277 0.22107585\n",
      "278 0.22058628\n",
      "279 0.22009888\n",
      "280 0.21961379\n",
      "281 0.21913089\n",
      "282 0.21865031\n",
      "283 0.21817188\n",
      "284 0.21769562\n",
      "285 0.21722165\n",
      "286 0.21674979\n",
      "287 0.21628003\n",
      "288 0.21581256\n",
      "289 0.21534714\n",
      "290 0.21488388\n",
      "291 0.21442258\n",
      "292 0.2139635\n",
      "293 0.21350637\n",
      "294 0.21305142\n",
      "295 0.21259856\n",
      "296 0.21214764\n",
      "297 0.21169873\n",
      "298 0.21125194\n",
      "299 0.21080701\n",
      "300 0.21036406\n",
      "301 0.20992316\n",
      "302 0.2094842\n",
      "303 0.2090472\n",
      "304 0.20861211\n",
      "305 0.2081789\n",
      "306 0.2077477\n",
      "307 0.20731826\n",
      "308 0.20689084\n",
      "309 0.20646523\n",
      "310 0.20604144\n",
      "311 0.20561957\n",
      "312 0.20519945\n",
      "313 0.20478125\n",
      "314 0.2043648\n",
      "315 0.20395015\n",
      "316 0.2035374\n",
      "317 0.20312618\n",
      "318 0.202717\n",
      "319 0.2023095\n",
      "320 0.20190383\n",
      "321 0.20149973\n",
      "322 0.20109743\n",
      "323 0.20069689\n",
      "324 0.20029786\n",
      "325 0.19990073\n",
      "326 0.19950515\n",
      "327 0.19911133\n",
      "328 0.19871914\n",
      "329 0.1983286\n",
      "330 0.19793975\n",
      "331 0.19755252\n",
      "332 0.19716689\n",
      "333 0.19678293\n",
      "334 0.19640054\n",
      "335 0.19601968\n",
      "336 0.19564039\n",
      "337 0.19526273\n",
      "338 0.19488665\n",
      "339 0.19451211\n",
      "340 0.19413912\n",
      "341 0.1937676\n",
      "342 0.19339773\n",
      "343 0.19302937\n",
      "344 0.19266254\n",
      "345 0.19229703\n",
      "346 0.19193321\n",
      "347 0.1915708\n",
      "348 0.19120982\n",
      "349 0.1908503\n",
      "350 0.19049229\n",
      "351 0.19013578\n",
      "352 0.1897806\n",
      "353 0.1894269\n",
      "354 0.1890747\n",
      "355 0.1887238\n",
      "356 0.18837437\n",
      "357 0.18802637\n",
      "358 0.1876797\n",
      "359 0.18733425\n",
      "360 0.18699045\n",
      "361 0.18664789\n",
      "362 0.18630673\n",
      "363 0.18596692\n",
      "364 0.18562838\n",
      "365 0.18529123\n",
      "366 0.18495536\n",
      "367 0.18462092\n",
      "368 0.18428768\n",
      "369 0.18395582\n",
      "370 0.18362516\n",
      "371 0.18329595\n",
      "372 0.18296787\n",
      "373 0.18264113\n",
      "374 0.18231556\n",
      "375 0.18199134\n",
      "376 0.18166839\n",
      "377 0.18134671\n",
      "378 0.18102624\n",
      "379 0.18070696\n",
      "380 0.18038888\n",
      "381 0.18007213\n",
      "382 0.1797565\n",
      "383 0.17944214\n",
      "384 0.17912897\n",
      "385 0.17881694\n",
      "386 0.17850608\n",
      "387 0.17819658\n",
      "388 0.1778881\n",
      "389 0.17758077\n",
      "390 0.1772746\n",
      "391 0.1769696\n",
      "392 0.1766658\n",
      "393 0.17636304\n",
      "394 0.17606153\n",
      "395 0.17576103\n",
      "396 0.17546174\n",
      "397 0.17516351\n",
      "398 0.17486645\n",
      "399 0.17457046\n",
      "400 0.17427553\n",
      "401 0.1739817\n",
      "402 0.17368892\n",
      "403 0.1733974\n",
      "404 0.17310679\n",
      "405 0.17281729\n",
      "406 0.17252883\n",
      "407 0.17224151\n",
      "408 0.17195508\n",
      "409 0.1716698\n",
      "410 0.17138556\n",
      "411 0.17110239\n",
      "412 0.17082018\n",
      "413 0.17053902\n",
      "414 0.17025882\n",
      "415 0.16997972\n",
      "416 0.16970153\n",
      "417 0.16942444\n",
      "418 0.16914833\n",
      "419 0.1688731\n",
      "420 0.16859905\n",
      "421 0.16832578\n",
      "422 0.16805369\n",
      "423 0.16778238\n",
      "424 0.16751209\n",
      "425 0.16724281\n",
      "426 0.16697444\n",
      "427 0.16670702\n",
      "428 0.16644056\n",
      "429 0.16617505\n",
      "430 0.16591044\n",
      "431 0.16564682\n",
      "432 0.16538404\n",
      "433 0.16512227\n",
      "434 0.16486132\n",
      "435 0.16460128\n",
      "436 0.16434228\n",
      "437 0.16408409\n",
      "438 0.16382678\n",
      "439 0.16357036\n",
      "440 0.16331488\n",
      "441 0.16306023\n",
      "442 0.16280656\n",
      "443 0.16255367\n",
      "444 0.16230163\n",
      "445 0.16205052\n",
      "446 0.16180027\n",
      "447 0.16155086\n",
      "448 0.16130224\n",
      "449 0.16105458\n",
      "450 0.16080765\n",
      "451 0.1605616\n",
      "452 0.1603164\n",
      "453 0.16007203\n",
      "454 0.15982856\n",
      "455 0.15958576\n",
      "456 0.15934388\n",
      "457 0.15910275\n",
      "458 0.15886247\n",
      "459 0.15862307\n",
      "460 0.15838437\n",
      "461 0.15814646\n",
      "462 0.15790942\n",
      "463 0.15767314\n",
      "464 0.15743764\n",
      "465 0.15720294\n",
      "466 0.15696903\n",
      "467 0.15673584\n",
      "468 0.15650348\n",
      "469 0.15627186\n",
      "470 0.15604094\n",
      "471 0.15581082\n",
      "472 0.15558144\n",
      "473 0.15535292\n",
      "474 0.15512496\n",
      "475 0.15489788\n",
      "476 0.15467156\n",
      "477 0.15444592\n",
      "478 0.15422106\n",
      "479 0.1539969\n",
      "480 0.15377344\n",
      "481 0.15355074\n",
      "482 0.15332875\n",
      "483 0.15310748\n",
      "484 0.15288688\n",
      "485 0.15266708\n",
      "486 0.15244803\n",
      "487 0.1522295\n",
      "488 0.15201184\n",
      "489 0.1517947\n",
      "490 0.1515784\n",
      "491 0.15136273\n",
      "492 0.15114774\n",
      "493 0.15093344\n",
      "494 0.15071985\n",
      "495 0.15050691\n",
      "496 0.15029466\n",
      "497 0.150083\n",
      "498 0.1498721\n",
      "499 0.14966184\n",
      "500 0.14945218\n",
      "501 0.14924325\n",
      "502 0.14903498\n",
      "503 0.14882736\n",
      "504 0.1486204\n",
      "505 0.14841402\n",
      "506 0.14820832\n",
      "507 0.14800324\n",
      "508 0.14779882\n",
      "509 0.14759506\n",
      "510 0.1473919\n",
      "511 0.14718942\n",
      "512 0.14698742\n",
      "513 0.1467862\n",
      "514 0.14658551\n",
      "515 0.14638546\n",
      "516 0.14618601\n",
      "517 0.14598726\n",
      "518 0.14578897\n",
      "519 0.14559136\n",
      "520 0.14539441\n",
      "521 0.14519797\n",
      "522 0.14500211\n",
      "523 0.14480701\n",
      "524 0.1446123\n",
      "525 0.1444183\n",
      "526 0.14422488\n",
      "527 0.14403203\n",
      "528 0.14383972\n",
      "529 0.14364797\n",
      "530 0.14345688\n",
      "531 0.1432663\n",
      "532 0.14307636\n",
      "533 0.14288694\n",
      "534 0.14269808\n",
      "535 0.14250979\n",
      "536 0.14232205\n",
      "537 0.14213493\n",
      "538 0.1419483\n",
      "539 0.14176226\n",
      "540 0.14157677\n",
      "541 0.14139175\n",
      "542 0.14120734\n",
      "543 0.14102352\n",
      "544 0.14084019\n",
      "545 0.14065732\n",
      "546 0.14047511\n",
      "547 0.14029342\n",
      "548 0.1401122\n",
      "549 0.13993156\n",
      "550 0.13975143\n",
      "551 0.13957186\n",
      "552 0.1393927\n",
      "553 0.13921417\n",
      "554 0.13903607\n",
      "555 0.13885859\n",
      "556 0.13868155\n",
      "557 0.13850504\n",
      "558 0.13832906\n",
      "559 0.13815355\n",
      "560 0.13797857\n",
      "561 0.13780414\n",
      "562 0.13763005\n",
      "563 0.13745663\n",
      "564 0.1372836\n",
      "565 0.13711107\n",
      "566 0.13693906\n",
      "567 0.13676757\n",
      "568 0.13659656\n",
      "569 0.13642605\n",
      "570 0.13625595\n",
      "571 0.13608633\n",
      "572 0.13591723\n",
      "573 0.13574862\n",
      "574 0.13558045\n",
      "575 0.13541281\n",
      "576 0.13524562\n",
      "577 0.13507883\n",
      "578 0.13491255\n",
      "579 0.13474676\n",
      "580 0.13458142\n",
      "581 0.13441654\n",
      "582 0.13425216\n",
      "583 0.1340881\n",
      "584 0.13392466\n",
      "585 0.1337616\n",
      "586 0.13359897\n",
      "587 0.13343686\n",
      "588 0.13327515\n",
      "589 0.13311383\n",
      "590 0.13295308\n",
      "591 0.1327927\n",
      "592 0.1326327\n",
      "593 0.13247329\n",
      "594 0.1323142\n",
      "595 0.13215555\n",
      "596 0.13199736\n",
      "597 0.13183968\n",
      "598 0.1316823\n",
      "599 0.13152543\n",
      "600 0.13136896\n",
      "601 0.13121289\n",
      "602 0.13105726\n",
      "603 0.13090204\n",
      "604 0.1307473\n",
      "605 0.13059293\n",
      "606 0.130439\n",
      "607 0.13028547\n",
      "608 0.13013232\n",
      "609 0.12997964\n",
      "610 0.1298273\n",
      "611 0.1296754\n",
      "612 0.12952395\n",
      "613 0.12937286\n",
      "614 0.12922217\n",
      "615 0.12907185\n",
      "616 0.128922\n",
      "617 0.12877256\n",
      "618 0.12862344\n",
      "619 0.12847473\n",
      "620 0.12832642\n",
      "621 0.1281785\n",
      "622 0.12803099\n",
      "623 0.12788388\n",
      "624 0.12773713\n",
      "625 0.12759076\n",
      "626 0.12744479\n",
      "627 0.12729917\n",
      "628 0.12715398\n",
      "629 0.12700914\n",
      "630 0.1268647\n",
      "631 0.12672062\n",
      "632 0.1265769\n",
      "633 0.12643361\n",
      "634 0.12629063\n",
      "635 0.12614807\n",
      "636 0.12600584\n",
      "637 0.12586401\n",
      "638 0.12572251\n",
      "639 0.12558138\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "640 0.12544061\n",
      "641 0.12530023\n",
      "642 0.12516019\n",
      "643 0.12502049\n",
      "644 0.1248812\n",
      "645 0.12474226\n",
      "646 0.12460361\n",
      "647 0.124465406\n",
      "648 0.12432748\n",
      "649 0.12418994\n",
      "650 0.12405273\n",
      "651 0.12391591\n",
      "652 0.12377943\n",
      "653 0.12364322\n",
      "654 0.123507455\n",
      "655 0.12337197\n",
      "656 0.12323687\n",
      "657 0.12310205\n",
      "658 0.12296757\n",
      "659 0.12283351\n",
      "660 0.12269969\n",
      "661 0.12256631\n",
      "662 0.12243317\n",
      "663 0.12230041\n",
      "664 0.12216797\n",
      "665 0.12203586\n",
      "666 0.12190409\n",
      "667 0.12177262\n",
      "668 0.1216415\n",
      "669 0.121510744\n",
      "670 0.12138023\n",
      "671 0.12125005\n",
      "672 0.12112023\n",
      "673 0.120990716\n",
      "674 0.12086152\n",
      "675 0.12073268\n",
      "676 0.1206041\n",
      "677 0.12047582\n",
      "678 0.12034792\n",
      "679 0.120220274\n",
      "680 0.120093\n",
      "681 0.11996602\n",
      "682 0.11983937\n",
      "683 0.11971295\n",
      "684 0.1195869\n",
      "685 0.11946115\n",
      "686 0.11933571\n",
      "687 0.11921054\n",
      "688 0.11908571\n",
      "689 0.11896112\n",
      "690 0.11883695\n",
      "691 0.118712954\n",
      "692 0.11858931\n",
      "693 0.11846595\n",
      "694 0.118342936\n",
      "695 0.118220136\n",
      "696 0.1180977\n",
      "697 0.11797549\n",
      "698 0.117853634\n",
      "699 0.117732055\n",
      "700 0.11761077\n",
      "701 0.11748976\n",
      "702 0.117369026\n",
      "703 0.117248565\n",
      "704 0.117128395\n",
      "705 0.11700855\n",
      "706 0.11688901\n",
      "707 0.11676967\n",
      "708 0.11665066\n",
      "709 0.11653192\n",
      "710 0.1164135\n",
      "711 0.11629535\n",
      "712 0.116177425\n",
      "713 0.11605982\n",
      "714 0.11594243\n",
      "715 0.11582536\n",
      "716 0.115708575\n",
      "717 0.11559205\n",
      "718 0.115475796\n",
      "719 0.11535987\n",
      "720 0.11524411\n",
      "721 0.1151287\n",
      "722 0.11501353\n",
      "723 0.11489861\n",
      "724 0.114783965\n",
      "725 0.11466961\n",
      "726 0.11455547\n",
      "727 0.11444165\n",
      "728 0.11432809\n",
      "729 0.11421476\n",
      "730 0.114101715\n",
      "731 0.113988884\n",
      "732 0.11387633\n",
      "733 0.11376407\n",
      "734 0.11365202\n",
      "735 0.11354024\n",
      "736 0.113428734\n",
      "737 0.11331749\n",
      "738 0.1132065\n",
      "739 0.11309574\n",
      "740 0.11298523\n",
      "741 0.11287491\n",
      "742 0.11276496\n",
      "743 0.1126552\n",
      "744 0.11254573\n",
      "745 0.11243644\n",
      "746 0.11232743\n",
      "747 0.11221863\n",
      "748 0.11211017\n",
      "749 0.11200186\n",
      "750 0.11189385\n",
      "751 0.11178605\n",
      "752 0.11167847\n",
      "753 0.11157119\n",
      "754 0.11146408\n",
      "755 0.11135729\n",
      "756 0.11125069\n",
      "757 0.11114435\n",
      "758 0.11103827\n",
      "759 0.11093234\n",
      "760 0.11082674\n",
      "761 0.11072132\n",
      "762 0.11061609\n",
      "763 0.11051117\n",
      "764 0.11040648\n",
      "765 0.11030203\n",
      "766 0.11019772\n",
      "767 0.11009375\n",
      "768 0.10998993\n",
      "769 0.109886386\n",
      "770 0.10978299\n",
      "771 0.1096799\n",
      "772 0.10957705\n",
      "773 0.10947435\n",
      "774 0.10937193\n",
      "775 0.109269716\n",
      "776 0.10916773\n",
      "777 0.109065995\n",
      "778 0.10896441\n",
      "779 0.1088631\n",
      "780 0.10876201\n",
      "781 0.10866108\n",
      "782 0.10856043\n",
      "783 0.10846002\n",
      "784 0.10835976\n",
      "785 0.10825972\n",
      "786 0.10815999\n"
     ]
    }
   ],
   "source": [
    "with tf.Session() as sess:\n",
    "    sess.run(tf.global_variables_initializer())\n",
    "    prev_err=0\n",
    "    for epoch in range(training_epochs):\n",
    "        err,_=sess.run([cost,train_op],{X1:x1s, X2:x2s, Y:ys})\n",
    "        print(epoch,err)\n",
    "        if abs(prev_err-err)<0.0001:\n",
    "            break\n",
    "        prev_err = err\n",
    "    w_val=sess.run(w,{X1:x1s,X2:x2s,Y:ys})"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [],
   "source": [
    "x1_boundary=[]\n",
    "x2_boundary=[]\n",
    "for x1_test in np.linspace(0,10,100):\n",
    "    for x2_test in np.linspace(0,10,100):\n",
    "        z=sigmoid(-x2_test*w_val[2] - x1_test*w_val[1] - w_val[0])\n",
    "        if abs(z-0.5) <0.01:\n",
    "            x1_boundary.append(x1_test)\n",
    "            x2_boundary.append(x2_test)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "plt.scatter(x1_boundary,x2_boundary,c='b',marker='o',s=20)\n",
    "plt.scatter(x1_label1,x2_label1,c='r',marker='x',s=20)\n",
    "plt.scatter(x1_label2,x2_label2,c='g',marker='1')"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
